#!/bin/sh

root_path=`dirname "$0"`
cd $root_path
root_path=$PWD
service_name=$(basename $PWD)

python_bin_path=$root_path/python3/bin
export PATH=$python_bin_path:$PATH

echo "path $root_path"
echo "stop $service_name"

PIDS=$(ps ax | grep -i python3 | grep $service_name | grep -v grep | awk '{print $1}')
if [ "$PIDS" ]; then
  echo "stop $service_name [kill -15" $PIDS]
  kill -15 $PIDS
  sleep 3
  PIDS=$(ps ax | grep -i python3 | grep $service_name | grep -v grep | awk '{print $1}')
  if [ "$PIDS" ]; then
    echo "stop $service_name [kill -9" $PIDS]
    kill -9 $PIDS
  fi
else
  echo "$service_name not started"
fi
